﻿<%@ Application Language="C#" %>
<%@ Import Namespace="Portal.Core" %>
<%@ Import Namespace="Portal.Core.Security" %>
<%@ Import Namespace="Portal.Data.Security" %>
<script RunAt="server">

    private void Application_Start(object sender, EventArgs e)
    {
        //log4net.Config.XmlConfigurator.Configure();
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
    }
    private void Application_Error(object sender, EventArgs ea)
    {
        Exception e = Server.GetLastError().GetBaseException();

        if (e is SecurityException)
        {
            if (Portal.Data.PortalContext.CurrentUser != null)
            {
                HttpContext.Current.Session["error@msg"] = e.Message;
                Response.Redirect(CoreContext.basepath + "AccessDenied.aspx", true);
            }
            else
                Response.Redirect(CoreContext.basepath + "admin_login.aspx", true);
        }
        else if (e is AccessException)
        {
            HttpContext.Current.Session["error@msg"] = e.Message;
            Response.Redirect(CoreContext.basepath + "AccessDenied.aspx", true);
        }
        else if (e is HttpNotFoundException)
        {
            Response.Redirect("/er404/");
        }
//        else if (e is HttpException)
//        {
//            var he = (HttpException)e;
//            switch (he.GetHttpCode())
//            {
//                case 404:
//                    Server.Transfer("~/Default.aspx?portalpage=ER404");
//                    break;
//                case 503:
//                    Server.Transfer("~/Default.aspx?portalpage=ER503");
//                    break;
//            }
//        }
    }


    private void Session_Start(object sender, EventArgs e)
    {

    }

    private void Session_End(object sender, EventArgs e)
    {
    }

   
</script>
